package install

import (
	"gitee.com/yangguoliang001/go-gin-vue3/config"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/file"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/response"
	"github.com/gin-gonic/gin"
	"net/http"
	"runtime"
)

type installController struct {
}

func New() *installController {
	return &installController{}
}

type TInstall struct {
	goMinVersion string
	goVersion    string
}

// Install  初始化配置
// @Summary 初始化数据库等配置
// @Description 初始化数据库等配置、mock
// @Tags API.install
// @Router /install [get]
//@Success 200 {object} TInstall
func (i *installController) Install() gin.HandlerFunc {
	return func(c *gin.Context) {
		if _, ok := file.IsExist(config.ProjectInstallMark); ok {
			c.Redirect(http.StatusTemporaryRedirect, "/")
		}
		//如果没有初始化，返回具体信息
		response.Success(c, "请求成功", gin.H{
			"goMixVersion": config.MinGoVersion,
			"goVersion":    runtime.Version(),
		})
	}
}
